{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "34ad6d61",
   "metadata": {
    "toc": true
   },
   "source": [
    "<h1>Table of Contents<span class=\"tocSkip\"></span></h1>\n",
    "<div class=\"toc\"><ul class=\"toc-item\"><li><span><a href=\"#使用Flask-搭建Web最小应用\" data-toc-modified-id=\"使用Flask-搭建Web最小应用-1\"><span class=\"toc-item-num\">1&nbsp;&nbsp;</span>使用Flask 搭建Web最小应用</a></span></li><li><span><a href=\"#提交表单的内容在python中接收\" data-toc-modified-id=\"提交表单的内容在python中接收-2\"><span class=\"toc-item-num\">2&nbsp;&nbsp;</span>提交表单的内容在python中接收</a></span></li></ul></div>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7043134a",
   "metadata": {},
   "source": [
    "## 使用Flask 搭建Web最小应用\n",
    "* 使用select创建一个html页面:index.html\n",
    "* 使用Flsak中的 render_template 实现页面的路由跳转"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4c0f206e",
   "metadata": {},
   "outputs": [],
   "source": [
    "from flask import Flask\n",
    "from flask import render_template\n",
    "\n",
    "app = Flask(__name__)\n",
    "\n",
    "@app.route('/')\n",
    "def hello_world():\n",
    "    return render_template('index.html')\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    app.run()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "884f4edc",
   "metadata": {},
   "source": [
    "##  提交表单的内容在python中接收"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8144dff2",
   "metadata": {},
   "outputs": [],
   "source": [
    "from flask import Flask\n",
    "from flask import render_template,request\n",
    "import crawl_liepin\n",
    "\n",
    "app = Flask(__name__)\n",
    "\n",
    "@app.route('/')\n",
    "def index():\n",
    "    return render_template(\"index.html\")\n",
    "\n",
    "@app.route('/user_choose',methods = ['POST', 'GET'])\n",
    "def user_choose():\n",
    "    print(request.form['city'])\n",
    "    print(request.form['category'])\n",
    "    print(request.form['workexp'])\n",
    "    user_city = request.form['city']\n",
    "    user_category = request.form['category']\n",
    "    user_workexp = request.form['workexp']\n",
    "    crawl_results = crawl_liepin.crawl(城市 = user_city ,关键词=user_category,工作经验=user_workexp)\n",
    "    crawl_results_html = crawl_results.to_html()\n",
    "    return render_template(\"user_choose.html\",\n",
    "                           crawl_results_html=crawl_results_html)\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    app.run()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "68c8ce2c",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": true,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
